import { onMounted, onBeforeUnmount, ref } from 'vue'

export function useResize(callback) {
    const width = ref(window.innerWidth)
    const height = ref(window.innerHeight)

    const handleResize = () => {
        width.value = window.innerWidth
        height.value = window.innerHeight
        callback?.()
    }

    onMounted(() => window.addEventListener('resize', handleResize))
    onBeforeUnmount(() => window.removeEventListener('resize', handleResize))

    return { width, height }
}
